﻿using Cmp.Web.Common;
using Cmp.Web.IRepository;
using Cmp.Web.IService;
using Cmp.Web.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cmp.Web.Service
{
    /// <summary>
    /// 患者信息接口
    /// </summary>
    public class PatientService : IPatientService
    {
        private readonly IPatientProvide patProvide;
        public PatientService(IPatientProvide _patProvide)
        {
            patProvide = _patProvide;
        }
        public Task<PatientInfo> GetPatientInfoByCard(CardType CardType, string CardNum, out ExceptionAll exception)
        {
            Task<PatientInfo> result = null;
            if (!string.IsNullOrEmpty(CardNum))
            {
                result = patProvide.GetPatientInfoByCard(CardType,CardNum,out exception);
            }
            else
            {
                result = null;
                exception = new ExceptionAll();
                exception.errMsg="参数类型错误";
                exception.errMsgId = ErrorType.FunctionError;
            }
            return result;
        }

        public Task<PatientInfo> GetPatientInfoByPatientId(string patientId, out ExceptionAll exception)
        {
            Task<PatientInfo> result = null;
            if (!string.IsNullOrEmpty(patientId))
            {
                result = patProvide.GetPatientInfoByPatientId(patientId, out exception);
            }
            else
            {
                result = null;
                exception = new ExceptionAll();
                exception.errMsg = "参数类型错误";
                exception.errMsgId = ErrorType.FunctionError;
            }
            return result;
        }

        public Task<bool> PatientDocumentation(PatientInfo patient, out ExceptionAll exception)
        {
            Task<bool> result = Task.FromResult<bool>(false);
            if (patient!=null&&!string.IsNullOrEmpty( patient.PatientIdCard))
            {
                result = patProvide.PatientDocumentation(patient, out exception);
            }
            else
            {
                exception = new ExceptionAll();
                exception.errMsg = "参数类型错误";
                exception.errMsgId = ErrorType.FunctionError;
            }
            return result;
        }
    }
}
